#include <iostream>
#include <memory>
#include "Log.hpp"

#include "Reactor.hpp"
#include "Connection.hpp"
#include "Listener.hpp"
#include "Log.hpp"
#include "IOService.hpp"
#include "PackageParse.hpp"
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "Usage" << argv[0] << " port " << std::endl;
        return 0;
    }

    EnableScreen();

    uint16_t port = std::stoi(argv[1]);


    IOService hc(PackageParse::Parse);//IO通信无关协议，回调上层业务处理

    Listener listener(port,hc); // 负责连接的模块
    // 注册进入
    std::unique_ptr<Reactor> svr(std::make_unique<Reactor>());
    svr->AddConnection(listener.Sockfd(),
                       EPOLLIN | EPOLLET,
                       std::bind(&Listener::Accepter,&listener,std::placeholders::_1),nullptr,nullptr);

    svr->Dispatcher();
    return 0;
}